package Code;

public class Code53 {
    public static int maxSubArray(int[] nums) {
        int maxRes = nums[0];
        int maxCur = nums[0];
        for(int i = 1; i< nums.length; i++){
            maxCur = Math.max(maxCur+ nums[i], nums[i]);
            maxRes = Math.max(maxRes, maxCur);
        }
        return maxRes;
    }
    public static void main(String[] args) {
        System.out.println(maxSubArray(new int[]{-2,1,-3,4,-1,2,1,-5,4}));
    }
}
